﻿using CommonLib;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YouErYuanModels;

namespace YouErYuanBLL
{
    /// <summary>
    /// 通知发布
    /// </summary>
    public class TongzhiPublishBLL
    {
        public int Add(TongzhiPubsh model)
        {
            string sql = "INSERT INTO [dbo].[T_Notification]([id],[title],[contentWZ],[source],[creatTime],[schoolId],[coverImgURL]) VALUES(newid(),@title,@contentWZ,@source,getdate(),@schoolId,@coverImgURL)";
            object title = model.Title;
            object source = model.Source;
            object coverimgurl = model.Coverimgurl;
            object contentwz = model.Contentwz;
            object schoolId = model.Schoolid;
            if (string.IsNullOrEmpty(model.Title) || string.IsNullOrWhiteSpace(model.Title))
            {
                title = DBNull.Value;
            }
            if (string.IsNullOrEmpty(model.Source) || string.IsNullOrWhiteSpace(model.Source))
            {
                source = DBNull.Value;
            }
            if (string.IsNullOrEmpty(model.Contentwz) || string.IsNullOrWhiteSpace(model.Contentwz))
            {
                contentwz = DBNull.Value;
            }
            if (string.IsNullOrEmpty(model.Coverimgurl) || string.IsNullOrWhiteSpace(model.Coverimgurl))
            {
                coverimgurl = DBNull.Value;
            }
            if (string.IsNullOrEmpty(model.Schoolid) || string.IsNullOrWhiteSpace(model.Schoolid))
            {
                schoolId = DBNull.Value;
            }
            SqlParameter[] parames = {
                new SqlParameter("@title",title),
                new SqlParameter("@contentWZ",contentwz),
                new SqlParameter("@source",source),
                new SqlParameter("@schoolId",schoolId),
                new SqlParameter("@coverImgURL",coverimgurl)
            };
            int count = SQLHepler.ExecuteSql(sql, parames);
            return count;
        }

    }
}
